//
//  HomeTableViewController.swift
//  Weibo
//
//  Created by 鹏 周 on 15/12/12.
//  Copyright © 2015年 ycit. All rights reserved.
//

import UIKit

import AFNetworking

class HomeTableViewController: BaseTableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        visitorLoginView?.setupInfo("登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", imageName: nil)
        //实现网络请求
        let AFN = AFHTTPSessionManager()
        //get请求
        let urlString = "http://www.weather.com.cn/data/sk/101010100.html"
        // 200:表示成功
        //failed: unacceptable content-type: text/html 表示反序列化错误  使用 AFN最常见的错误 没有之一
        // 默认支持解析 @"application/json", @"text/json", @"text/javascript"
        AFN.responseSerializer.acceptableContentTypes?.insert("text/html")

        AFN.GET(urlString, parameters: nil, progress: { (p) -> Void in
            print(p)
            }, success: { (task, result) -> Void in
//                print(result)
                
                let weatherInfo = result!["weatherinfo"]
                let name = weatherInfo!!["city"] as! String
                let wd = weatherInfo!!["WD"] as! String
                let njd = weatherInfo!!["njd"] as! String
                let ws = weatherInfo!!["WS"] as! String
               
                print(name,wd,njd,ws)
                
               let view =  UIAlertView(title: "实时天气", message: "当前城市:\(name)\n 风向:\(wd)\n 风级:\(ws)", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "确定")
//               view.show()
            }) { (task, error) -> Void in
                print(error)
        }
    }
}
